package s08.ch10.homework;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class Truck extends Car {
	private Integer weight;

	public Truck(String color, BigDecimal price, Integer weigth) {
		super(color, price);
		setWeight(weigth);
	}

	public Integer getWeight() {
		return weight;
	}

	public void setWeight(Integer weight) {
		this.weight = weight;
	}

	

	public BigDecimal getDiscountedPrice() {
		if (getWeight() > 2000) {
			BigDecimal cena = getPrice();
			return cena;
		} else {
			double discountPercent = 0.1;
			BigDecimal decimalDiscountPercent = new BigDecimal(
					Double.toString(discountPercent));
			BigDecimal decimalSubtotal = getPrice();
			decimalSubtotal = decimalSubtotal
					.setScale(-1, RoundingMode.HALF_UP);
			BigDecimal discountAmount = decimalSubtotal
					.multiply(decimalDiscountPercent);
			BigDecimal discount = decimalSubtotal.subtract(discountAmount);
			return discount;
		}

	}
}
